package com.syh.jn.scm.domain.operation.TerminalAccountOfPhone;

import cn.redscarf.commons.util.other.ExtAssert;
import cn.redscarf.commons.util.secret.PasswordUtils;
import cn.redscarf.commons.wrapper.Restrictions;
import cn.redscarf.commons.wrapper.Wrapper;
import com.syh.jn.scm.domain.operation.entity.system.TerminalAccount;
import com.syh.jn.scm.domain.supplier.entity.system.SupplierAccount;
import com.syh.jn.scm.domain.supplier.repository.system.SupplierAccountRepository;
import com.syh.jn.scm.exception.BusinessException;
import com.syh.jn.scm.infrastructure.repository.impl.operation.system.TerminalAccountOfPhoneReadRepositoryImpl;
import com.syh.jn.scm.infrastructure.repository.impl.operation.system.TerminalAccountOfPhoneRepositoryImpl;
import com.syh.jn.scm.service.api.supplier.support.enums.SupplierEnums;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by soci.song on 2018/12/13.
 */
@Service
public class TerminalAccountOfPhoneDomainService {

  @Autowired
  private TerminalAccountOfPhoneRepositoryImpl terminalAccountOfPhoneRepository;


  public void clearCorrelation(Long id) {
    Wrapper we = Wrapper.build().append(Restrictions.eq("loginPhoneId", id));
    List<TerminalAccount> accounts = terminalAccountOfPhoneRepository.getAccountList(we);
    accounts.forEach(account -> {
      account.untyingLoginPhone();
      terminalAccountOfPhoneRepository.updateAccount(account);
    });
  }

  public void bindingAccount(Long id, Long accountId) {
    TerminalAccount account = terminalAccountOfPhoneRepository.getAccountById(accountId);
    account.bindingLoginPhone(id);
    terminalAccountOfPhoneRepository.updateAccount(account);
  }

  public void untyingAccount(Long id, Long accountId) {
    TerminalAccount account = terminalAccountOfPhoneRepository.getAccountById(accountId);
    account.untyingLoginPhone();
    terminalAccountOfPhoneRepository.updateAccount(account);
  }

  public List<TerminalAccount> getAccountListByPhoneId(Long id) {
    Wrapper we = Wrapper.build().append(Restrictions.eq("loginPhoneId", id));
    List<TerminalAccount> accounts = terminalAccountOfPhoneRepository.getAccountList(we);
    return accounts;
  }
}
